/* $$Id: RssFeed.java 33 2008-01-10 16:17:18Z qxodream $$
 *
 * RssReaderMidlet --  RSS reader for J2ME(midp)
 * The original codes of this porgram is from
 * RssOwlMIDlet(zhengyun@gmail.com)
 *
 * Copyright (c) 2007-2008 QXO(qxodream@gmail.com)
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

package com.ultrapower.model;

import java.io.UnsupportedEncodingException;
import java.util.*;

/**
 * 类说明： Rss Feed所对应的类实体，基本上有这么几个属性： 在RMS中存储的id序号;Feed名称，如“博客堂”或“博客园”；
 * Feed的URL，如http://blog.csdn.net/zhengyun_ustc/Rss.aspx；<BR/> RssFeed class
 * contains one RSS feed's properties. Properties include name and URL to RSS
 * feed.
 *
 * @author Tommi Laukkanen
 * @author QXO(qxodream@gmail.com)
 *
 */
public class RssFeed {

	private int m_id;
	private String m_url = "";
	private String m_name = "";
	protected Vector m_items = new Vector(); // The RSS item vector

	public RssFeed() {
		super();
	}

	/** Creates a new instance of RSSBookmark */
	public RssFeed(String name, String url) {
		m_name = name;
		m_url = url;
	}

	public RssFeed(int id, byte[] data) {
		this.m_id = id;
		String temp;
		try {
			temp = new String(data, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			temp = new String(data);
			e.printStackTrace();
		}

		int ind = temp.indexOf("|");
		if (ind != -1) {
			m_name = temp.substring(0, ind);
			m_url = temp.substring(ind + 1);
		}
	}

	/** Creates a new instance of RSSBookmark with record store string */
	public RssFeed(String storeString) {
		int i = storeString.indexOf("|");
		if (i > 0) {
			m_name = storeString.substring(0, i);
			m_url = storeString.substring(i + 1);
		}
	}

	public int getId() {
		return m_id;
	}

	public void setId(int id) {
		this.m_id = id;
	}

	/** Return bookmark's name */
	public String getName() {
		return m_name;
	}

	public void setName(String value) {
		this.m_name = value;
	}

	/** Return bookmark's URL */
	public String getUrl() {
		return m_url;
	}

	public void setUrl(String value) {
		this.m_url = value;
	}

	/** Return record store string */
	public String getStoreString() {
		return m_name + "|" + m_url;
	}

	/** Return RSS feed items */
	public Vector getItems() {
		return m_items;
	}

	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((m_url == null) ? 0 : m_url.hashCode());
		return result;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final RssFeed other = (RssFeed) obj;
		if (m_url == null) {
			if (other.m_url != null)
				return false;
		} else if (!m_url.equals(other.m_url))
			return false;
		return true;
	}

	public String toString() {
		StringBuffer sb = new StringBuffer("feed[name:");
		sb.append(this.m_name).append("\turl:").append(this.m_url);
		return sb.toString();
	}
}
